package net.mengkang;

import net.mengkang.utils.TraceUtil;

import javax.servlet.*;
import java.io.IOException;

public class TraceFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        TraceUtil.generate();

        System.out.printf("time:%s traceId:%s TraceFilter\n", System.currentTimeMillis(), TraceUtil.get());

        chain.doFilter(request, response);

        TraceUtil.remove();
    }

    @Override
    public void destroy() {

    }
}
